<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script type="text/javascript" src="static/js/jquery.min.js"></script>
    <script type="text/javascript"
            src="static/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap-treeview.min.css"
          th:href="@{static/js/bootstrap/css/bootstrap-treeview.min.css}"
    >
    <script src="static/js/bootstrap/js/bootstrap-treeview.min.js"></script>
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap.addtabs.css">
    <script src="static/js/bootstrap/js/bootstrap.addtabs.min.js"></script>
    <link rel="stylesheet" href="static//js/bootstrap/css/bootstrap-table.min.css">
    <script src="static/js/bootstrap/js/bootstrap-table.min.js"></script>
    <script src="static/js/bootstrap/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="static/js/bootstrap/js/bootbox.js"></script>
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap-datetimepicker.min.css" />
    <script type="text/javascript"
            src="static/js/bootstrap/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript"
            src="static/js/bootstrap/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="static/js/bootstrap-fileinput/js/fileinput.js"></script>
    <script src="static/js/bootstrap-fileinput/js/locales/zh.js"></script>
    <link rel="stylesheet" href="static/js/bootstrap-fileinput/css/fileinput.css">

</head>
<body>

<ul id="myTab" class="nav nav-tabs">
    <li>
        <a href="#home" data-toggle="tab">定制寻图单</a>
    </li>

    <li>
        <a href="#ios" data-toggle="tab">定制寻价单</a>
    </li>

    <li>
        <a href="#cailiao" data-toggle="tab">我的材料单</a>
    </li>
</ul>
<br>
<div id="myTabContent" class="tab-content">
    <!-- -----------------------------------------------------------以下是询图列表 -->
    <div class="tab-pane fade" id="home">

        <!-- 延期 -->
        <form id="myform_cyt" method="post">
            <div class="modal fade" id="myModal_cyt" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title">延期</h4>
                        </div>
                        <input hidden="hidden" name="queryPictureRequirementType">
                        <input hidden id="yanqi_id">
                        <div class="form-group">
                            <input type="date" name="queryPictureStartDate" class="form-control" placeholder="请输入开始日期">
                        </div>

                        <div class="form-group">
                            <input type="date" name="queryPictureEndDate" class="form-control" placeholder="请输入截止日期">
                        </div>
                        <input type="button" class="btn" onclick="updateYanQi()" value="确定">
                    </div>
                </div>
            </div>
        </form>

        <!-- 条件查询 -->
        <div style="background-color: #afd9ee;height: 40px;padding: 3px">
            <form class="form-inline" role="form">
                <div class="form-group">
                    <label>项目名称：</label>
                    <input type="text" name="productName" id="QueryproductName" class="form-control" placeholder="请输入产品名称">
                </div>
                <div class="form-group" style="margin-left: 30px">
                    <label>状态：</label>
                    <select class="form-control" name="queryPictureState" id="queryPictureState">
                        <option value="-1">请选择</option>
                        <option value="1">即将开始</option>
                        <option value="4">未发布</option>
                        <option value="5">待接单</option>
                        <option value="6">待出图</option>
                        <option value="7">待定图</option>
                        <option value="8">已定图</option>
                        <option value="9">已失效</option>
                        <option value="10">已取消</option>
                    </select>
                </div>

                <div class="form-group" style="margin-left: 20px">
                    <label>开始时间：</label>
                    <input type="date" id="queryPictureStartDate" class="form-control">
                </div>
                <div class="form-group" style="margin-left: 5px">
                    —
                </div>

                <div class="form-group" style="margin-left: 5px">
                    <label>结束时间时间：</label>
                    <input type="date" id="queryPictureEndDate" class="form-control">
                </div>
                <input type="button" style="margin-left: 10px" class="btn" onclick="selectByQuery()" value="搜索">
            </form>
        </div>
        <br>
            <button type="button" id="button_add_1" value="1" onclick="addPicture()" class="btn btn-primary">我要发布定制比价</button>
        <br>
        <br>
        <table id="table"></table>

        <!-- 取消 -->
        <form id="cancelFrom" method="post">
            <div class="modal fade" id="cancelModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">


                        <div class="modal-header">
                            <h4 class="modal-title">取消询价单</h4>
                        </div>

                        <br>
                        取消原因
                        <br>
                        <br>
                        <center>
                            <input hidden id="cancelById">
                            <label class="radio-inline">
                                <input type="radio" name="cancel" value="项目变更">项目变更
                            </label>
                            <label class="radio-inline" style="margin-left: 200px">
                                <input type="radio" name="cancel" value="其他">其他
                            </label>
                            <br>
                            <div class="form-group">
                                <textarea class="form-control" rows="5" name="cancelText" style="width: 550px" placeholder="请输入取消寻图单原因，不能超过50字"></textarea>
                            </div>
                        </center>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>取消</button>
                            <input type="button" onclick="confirmCancel()" class="btn btn-default" value="确定">
                        </div>

                    </div>
                </div>
            </div>
        </form>

    </div>

    <!-- -------------------------------------------------------以下是询价列表 -->

    <div class="tab-pane fade" id="ios">
        <form class="form-inline" role="form">
            <!-- 条件查询 -->
            <div class="center-pill" style="background:#afd9ee;display:flex">
                &nbsp;
                <div class="form-group">
                    <label>项目名称:</label>

                    <input type="text" autocomplete="off" id="productName" placeholder="请输入项目名称" class="form-control" style="width: 200px;margin-left:10px">
                </div>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                <div class="form-group">
                    <label>状态：</label>
                    <select class="form-control" id="queryPriceStatus">
                        <option value="0">全部</option>
                        <option value="1">即将开始</option>
                        <option value="2">报价中</option>
                        <option value="3">正在进行</option>
                        <option value="4">已失效</option>
                        <option value="5">已取消</option>
                        <option value="6">已定标</option>
                        <option value="7">待定标</option>
                    </select>
                </div>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <div class="form-group">
                    <label>活动时间：</label>
                    <input type="date" autocomplete="off" id="queryPriceStartDate" placeholder="开始时间" class="form-control" style="width: 200px;margin-left:10px">---
                </div>
                <div class="form-group">
                    <input type="date" autocomplete="off" id="queryPriceEndDate" placeholder="结束时间" class="form-control" style="width: 200px;margin-left:10px">
                </div>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <!-- 查询按钮 -->
                <input style="margin-left:10px" class='btn btn-default' type='button' onclick='queryData()' value='搜索'>
            </div>
        </form>
        <!-- 新增表单 -->
        <form id="myform" method="post">
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">

                        <div class="modal-header">
                            <h4 class="modal-title" id="myModalLabel">延期</h4>
                        </div>
                        <!- 主表Id隐藏域 ->
                        <input type="hidden" name="productId" id="productId">

                        <div class="form-group">
                            <label for="queryPriceEndDate1">设置结束日期</label>
                            <input type="date" class="form-control" id="queryPriceEndDate1" placeholder="设置结束日期" name="queryPriceEndDate">
                        </div><br>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
                            <input value="保存" type="button" class="btn" onclick="save()">
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <br>
        <button type="button" onclick="addPicture1()" id="button_add_2" value="2" class="btn btn-primary">我要发布定制比价</button>
        <br>
        <table id="myTable"></table>

        <input id="input1"  type="hidden">
    </div>

    <!-- ---------------------------------以下是我的材料单  -->
    <div class="tab-pane fade" id="cailiao">
        <table id="cailiao_table_cai"></table>
    </div>
</div>

</body>

<script>

    var button_add_2 = $("#button_add_2").val()


    function addPicture1(){
        location.href="findCustomized.html"
    }

    var button_add_1 = $("#button_add_1").val()
    function addPicture(){
        location.href="findCustomized.html"
    }

    $(function () {
        $('#myTab li:eq(0) a').tab('show');
        init();
        init2();
        findcailiao_table_cai();
    });

    function init(){

        $("#myTable").bootstrapTable({
            // $("#table").bootstrapTable('destory'),
            url:"findProduct",
            columns:[
                {field:'checkbox',checkbox:true},
                {field:'productId',title:'项目编码'},
                {field:'productName',title:'项目名称'},
                {field:'queryPriceStartDate',title:'开始时间'},
                {field:'queryPriceEndDate',title:'结束时间'},
                {field:'productCount',title:'参与数量'},
                {field:'queryPriceStatus',title:'状态',formatter:function(value,row){
                        if (value == 1){
                            return "即将开始";
                        }else if (value == 2){
                            return "报价中";
                        }else if (value == 3){
                            return "正在进行";
                        }else if (value == 4){
                            return "已失效";
                        }else if (value == 5){
                            return "已取消";
                        }else if (value == 6){
                            return "已定标";
                        }else if (value == 7){
                            return "待定标";
                        }else if (value == 14){
                            return "已中标";
                        }
                    }},
                {field:'cz',title:'操作',formatter:function(value,row){
                        str = '';
                        if (row.queryPriceStatus == 1){
                            str += '<button onclick="updatePicture_cyt(\''+row.productId+'\')" class="btn btn-warning">修改询价单</button>';
                            str += '<button onclick="cancelEnquiry(\''+row.productId+'\')" class="btn btn-warning">取消询价单</button>';
                        }else if (row.queryPriceStatus == 2){
                            str += '<button onclick="selectEnquiry(\''+row.productId+'\')" class="btn btn-warning">查看报价</button>';
                            str += '<button onclick="updatePicture_cyt(\''+row.productId+'\')" class="btn btn-warning">修改询价单</button>';
                            str += '<button onclick="postpone(\''+row.productId+'\')" class="btn btn-warning">延期</button>';
                            str += '<button onclick="cancelEnquiry(\''+row.productId+'\')" class="btn btn-warning">取消询价单</button>';
                        }else if (row.queryPriceStatus == 3){
                            str += '<button onclick="selectEnquiry(\''+row.productId+'\')" class="btn btn-warning">查看报价</button>';
                        }else if (row.queryPriceStatus == 4){
                            str += '<button onclick="resend(\''+row.productId+'\')" class="btn btn-warning">重新发起</button>';
                        }else if (row.queryPriceStatus == 5){
                            str += '<button onclick="resend(\''+row.productId+'\')" class="btn btn-warning">重新发起</button>';
                        }else if (row.queryPriceStatus == 6){
                            str += '<button onclick="selectEnquiry(\''+row.productId+'\')" class="btn btn-warning">查看报价</button>';
                            str += '<button onclick="selectOrderForm(\''+row.productId+'\')" class="btn btn-warning">查看订单</button>';
                        }else if (row.queryPriceStatus == 7){
                            str += '<button onclick="selectEnquiry(\''+row.productId+'\')" class="btn btn-warning">查看报价</button>';
                            str += '<button onclick="cancelEnquiry(\''+row.productId+'\')" class="btn btn-warning">取消询价单</button>';
                        }
                        return str;
                    }},
            ],
            //开启分页以后，默认会传入两个参数,而这两个参数，直接是mysql的分页计算后的数据
            pagination:true,
            pageSize:10,
            pageList:[10,20,30,40,50],
            sidePagination : 'client',//server:服务器端分页{rows:[],total:10}|client：前端分页 [{},{}]
        })
    }
    /* 条件查询 */
    function queryData(){
        $("#myTable").bootstrapTable("refresh", {
            "query": {
                "productName": $("#productName").val(),
                "queryPriceStatus": $("#queryPriceStatus").val(),
                "queryPriceStartDate": $("#queryPriceStartDate").val(),
                "queryPriceEndDate": $("#queryPriceEndDate").val(),
            }
        });
    }
    /* 取消询价单 */
    function cancelEnquiry(productId){
        $.ajax({
            url:"cancelEnquiry?productId="+productId,
            success:function(){
                alert("已取消")
                /*刷新表格*/
                $("#myTable").bootstrapTable("refresh")
            }
        })
    }

    /* 重新发起 */
    function resend(productId){
        $.ajax({
            url:"resend?productId="+productId,
            success:function(){
                alert("发起成功,即将进入页面");
                /*刷新表格*/
                $("#myTable").bootstrapTable("refresh")
            }
        })
    }
    /*延期回显*/
    function postpone(productId){
        $('#myModal').modal("show");
        $.ajax({
            url: 'postpone?productId='+productId,
            success: function (data) {
                /*需要回显的话用下面的方法 需要传Id的话加Id*/
                $("input[name='productId']").val(data.queryPriceRequirementType);
                $("input[name='queryPriceEndDate']").val(data.queryPriceEndDate);
            }
        })
    }
    /* 延期修改 */
    function save(productId){
        var id =  $('#productId').val();
        var queryEndDate = $('#queryPriceEndDate1').val();
        $.ajax({
            url:"save",
            data:{id:id,queryEndDate:queryEndDate},
            type:"post",
            dateType:"json",
            success:function(data){
                $('#myModal').modal("hide");
                $("#myTable").bootstrapTable("refresh")
            }
        })
    }

    /* 修改询价单取前台Id */
    function updateEnquiry(productId) {
        location.href = "updateEnquiry?productId="+productId;
    }

    /* 修改询价单回显 */
    function updateEnquiry() {
        var id = $("#span1").val()
        $.ajax({
            url: "getById?id="+id,
            success: function (data) {
                $("[value="+data.queryPriceStartDate+"]").prop("checked",true);
                $("input[name='queryPriceEndDate']").val(data.queryPriceEndDate);
                $("[value="+data.biddingEndDate+"]").prop("checked",true);
                $("input[name='biddingEndDate']").val(data.biddingEndDate);
                $("[value="+data.receiveGoodsDay+"]").prop("checked",true);
                $("input[name='queryPriceCompanyCountMin']").val(data.queryPriceCompanyCountMin);
                $("input[name='expectTotal']").val(data.expectTotal);

                $("input[name='address']").val(data.address);
                $("input[name='purchasingDepartmentId']").val(data.productCount);
                $("input[name='departmentOrganizationId']").val(data.productCount);
                $("input[name='defaultPlant']").val(data.productCount);
                $("input[name='defaultInventory']").val(data.productCount);
                $("input[name='queryPriceRemark']").val(data.queryPriceRemark);
                // <img id="queryPriceAccessory" width="100px" height="100px" />

                $("#queryPriceAccessory").attr("src",data.queryPriceAccessory)	//赋值
                $("[value="+data.supplyMaterial+"]").prop("checked",true);
            }
        })
    }
    /* ------------------------------寻图列表 */
    function init2(){
        $("#table").bootstrapTable({
            url:"getPicture",
            columns:[
                {field:'productId',title: '项目编号'},
                {field:'productName',title:'项目名称'},
                {field:'queryPictureStartDate',title:'开始时间'},
                {field:'queryPictureEndDate',title:'结束时间'},
                {field:'queryPictureState',title:'状态',formatter:function(value){
                    if (value == 1){
                        return "即将开始"
                    }else if(value == 4){//
                        return "未发布"
                    }else if(value == 10){//
                        return "已取消"
                    }else if(value==9){//
                        return "已失效"
                    }else if(value == 5){
                        return "待接单"
                    }else if(value == 6){//
                        return "待出图"
                    }else if(value == 7){//
                        return "待定图"
                    }else{
                        if(value == 8){//
                            return "已定图"
                        }
                    }
                }},
                {field:'cz',title:'操作',formatter:function(value,row){
                    var str = ""
                        if (row.queryPictureState != 9 && row.queryPictureState != 10 && row.queryPictureState != 8){
                            str+="<input type='button' onclick='updatePicture_cyt(\""+row.productId+"\")' class='btn' value='修改寻图单'>"
                            str+="<input type='button' onclick='cancelById_cyt(\""+row.productId+"\")' class='btn' value='取消寻图单'>"
                            str+="<input type='button' onclick='delById_cyt(\""+row.productId+"\")' class='btn' value='删除寻图单'>"
                            str+="<input type='button' onclick='postpone_cyt(\""+row.productId+"\")' class='btn' value='延期'>"
                        }
                        if (row.queryPictureState == 10 && row.queryPictureState != 8){
                            str+="<input type='button' onclick='toInitiatePicture_cyt(\""+row.productId+"\")' class='btn' value='重新发起'>"
                        }
                        if (row.queryPictureState==7 && row.queryPictureState != 8){
                            str+="<input type='button' onclick='findImgData(\""+row.productId+"\")' class='btn' value='查看'>"
                        }
                        if (row.queryPictureState == 8){
                            str+="<input type='button' onclick='findParticulars(\""+row.productId+"\")' class='btn' value='查看详情'>"
                        }
                    return str;
                }},
            ],

            pagination:true,//是否启用分页4

            pageSize:3,//每页的记录行数（*）
            pageList:[3,6,9],//可供选择的每页的行数（*）
            showRefresh: false,//是否显示刷新按钮
            cardView: false,//是否显示详细视图
            sidePagination: "client",//分页方式：client客户端分页，server服务端分页（*）
            cache: false,//是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        })
    }

    function findParticulars(productId){
        location.href="findParticulars?productId="+productId
    }

    function findImgData(productId){
        location.href="findImgData?productId="+productId
    }

    /* 重新发起 */
    function toInitiatePicture_cyt(productId){
        $.ajax({
            url:"toInitiatePicture_cyt?productId="+productId,
            type:"get",
            success:function(data){
                alert("重新发起成功");
                $("#table").bootstrapTable("refresh")
            }
        })
    }

    /* 回显 */
    function updatePicture_cyt(productId){
        location.href="upUpdatePicture_cyt?productId="+productId
    }

    /* 取消寻图 */
    function cancelById_cyt(productId){
        document.getElementById("cancelFrom").reset();//重置表单
        $('#cancelModal').modal("show");
        $("#cancelById").val(productId)
    }

    function confirmCancel(){
        var productId = $("#cancelById").val()
        var cancel = $("input[name='cancel']").val();
        $.ajax({
            url:"/cancelById_cyt?productId="+productId,
            type:"get",
            dataType:"json",
            success:function(data){
                $('#cancelModal').modal("hide");
                $("#table").bootstrapTable("refresh")
            },
            error:function(){
            }
        })
    }

    /* 寻图删除方法 */
    function delById_cyt(productId){
        $.ajax({
            url:"delById_cyt?productId="+productId,
            success:function(data){
                alert("删除成功")
                $("#table").bootstrapTable("refresh")
            }
        })
    }

    function selectEnquiry(productId) {
        //alert(productId)
        location.href = "selectEnquiry?productId="+productId;
    }

    /* 延期 */
    function postpone_cyt(productId){
        document.getElementById("myform_cyt").reset();
        $('#myModal_cyt').modal("show");
        $.ajax({
            url: 'selYanQiById?productId='+productId,
            success: function (data) {
                $("input[name='queryPictureRequirementType']").val(data.queryPictureRequirementType);
                $("input[name='queryPictureStartDate']").val(data.queryPictureStartDate);
                $("input[name='queryPictureEndDate']").val(data.queryPictureEndDate);
            }
        })
    }

    function updateYanQi(){
        $.ajax({
            url:"updateYanQi",
            data:$("#myform_cyt").serialize(),
            success:function(data){
                $('#myModal_cyt').modal("hide");
                $("#table").bootstrapTable("refresh")
            }
        })
    }

    /* 条件查询 */
    function selectByQuery(){
        $("#table").bootstrapTable("refresh", {
            "query": {
                "productName":$("#QueryproductName").val(),
                "queryPictureState":$("#queryPictureState").val(),
                "queryPictureStartDate":$("#queryPictureStartDate").val(),
                "queryPictureEndDate":$("#queryPictureEndDate").val()
            }
        });
    }

    /* -----------------------以下是我的材料单 */
    /* 查询 */
    function findcailiao_table_cai(){

        $("#cailiao_table_cai").bootstrapTable({
            url:"findBillOfMaterialsData",
            columns:[
                {field:'materialsType',title:'类目'},
                {field:'materialsName',title:'材料名称'},
                {field:'materialsId',title:'材料编码'},
                {field:'materialsCount',title:'材料数量'},
            ],
            pagination:true,//是否启用分页
            pageSize:3,//每页的记录行数（*）
            pageList:[3,6,9],//可供选择的每页的行数（*）
            showRefresh: false,//是否显示刷新按钮
            cardView: false,//是否显示详细视图
            sidePagination: "client",//分页方式：client客户端分页，server服务端分页（*）
            cache: false,//是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        })
    }

</script>

</html>